import datetime

from django.db import models



class AuditBash(models.Model):
    host_ip = models.GenericIPAddressField(verbose_name='主机IP')
    run_user = models.CharField(verbose_name='用户', max_length=128)
    client = models.GenericIPAddressField(verbose_name='来自于')
    tty = models.CharField(max_length=32, verbose_name='tty')
    run_time = models.DateTimeField(verbose_name='执行时间')
    history_id = models.IntegerField(verbose_name='命令id')
    cmd = models.CharField(max_length=512, verbose_name='bash命令')
    send_time = models.DateTimeField(verbose_name='发送时间')
    create_time = models.DateTimeField(default=datetime.datetime.now, verbose_name='创建时间')
    is_danger = models.BooleanField(default=False)
    
    class Meta:
        verbose_name = 'Bash 命令审计'
        verbose_name_plural = verbose_name
    
    def __unicode__(self):
        return "{}:{}".format(self.host_ip, self.history_id)
    
    